const Koa = require('koa')
const serve = require('koa-static')

// 处理history模式路径问题的中间件
const  { historyApiFallback } = require('koa2-connect-history-api-fallback')
const app = new Koa()

// 除了接口之外的请求都发送给index.html
app.use(historyApiFallback({
  whiteList: ['/api']
}))

// 配置跨域代理
const proxy = require('koa2-proxy-middleware')
app.use(proxy({
  targets: {
    '/api/(.*)': {
      target: 'http://ihrm-java.itheima.net',
      changeOrigin: true
    }
  }
}))

app.use(serve(__dirname + '/public'))

app.listen(3333,() => {
  console.log('服务器启动成功! 127.0.0.7:3333');
})